home *** CD-ROM | disk | FTP | other *** search
- #include <ApplicationServices/ApplicationServices.h>
- #include <Carbon/Carbon.h>
- #include <stdio.h>
- #include <unistd.h>
- #include "FinderPatch.h"
- #include "MachOUtils.h"
-
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- typedef UInt32 CGSConnectionID;
-
- extern CGSConnectionID _CGSDefaultConnection(void);
- extern OSStatus CGSSetWindowOpacity(CGSConnectionID connID,CGSConnectionID winID,int isOpaque);
- extern OSStatus CGSSetWindowAlpha(CGSConnectionID connID,CGSConnectionID winID,float alpha);
- extern OSStatus CGSLockWindowBits(CGSConnectionID connID,CGSConnectionID winID,CGRect *bounds,UInt32 *depth,void *data,SInt32 *rows);
- extern OSStatus CGSUnlockWindowBits(CGSConnectionID connID,CGSConnectionID winID,void *updateRgn);
-
- extern void *GetNativeWindowFromWindowRef(WindowRef window);
- extern WindowRef GetWindowRefFromNativeWindow(void *window);
-
- typedef void (*CopyBitsProcPtr)(const BitMap *srcBits,const BitMap *dstBits,const Rect *srcRect,
- const Rect *dstRect,SInt16 mode,RgnHandle maskRgn);
-
- void Initialize(void);
- static void PowerPlant_CopyBitsPatch(const BitMap *srcBits,const BitMap *dstBits,const Rect *srcRect,
- const Rect *dstRect,SInt16 mode,RgnHandle maskRgn);
-
- #ifdef __cplusplus
- }
- #endif
-
-
-
- #define kPowerPlantPath "/System/Library/PrivateFrameworks/PowerPlant.framework/PowerPlant"
-
-
-
- CGSConnectionID gCGSConnID = _CGSDefaultConnection();
- CGSConnectionID gDesktopWindow = NULL;
- WindowRef gDesktopWindowRef = NULL;
- CopyBitsProcPtr *gPowerPlant_CopyBitsVector = (CopyBitsProcPtr*)FindSymbolAddress(kPowerPlantPath,"_CopyBits");
- CopyBitsProcPtr gPowerPlant_CopyBitsProc = NULL;
-
-
-
- void Initialize(void)
- {
- SInt32 x,y;
- WindowRef window;
- Rect bounds;
- OSStatus err;
-
- if (gPowerPlant_CopyBitsVector == NULL) {
- fprintf(stderr,"Unresolved vector: PowerPlant_CopyBits");
- return;
- }
-
- gDesktopWindowRef = NULL;
- for (window = GetWindowList();window != NULL;window = MacGetNextWindow(window))
- {
- GetWindowBounds(window,kWindowContentRgn,&bounds);
- if ((gDesktopWindowRef == NULL) ||
- ((bounds.right - bounds.left) > x) ||
- ((bounds.bottom - bounds.top) > y))
- {
- gDesktopWindowRef = window;
- x = bounds.right - bounds.left;
- y = bounds.bottom - bounds.top;
- }
- }
-
- gDesktopWindow = (CGSConnectionID)GetNativeWindowFromWindowRef(gDesktopWindowRef);
-
- err = CGSSetWindowOpacity(gCGSConnID,gDesktopWindow,false);
- if (err != noErr) {
- fprintf(stderr,"CGSSetWindowOpacity failed: %08lX, %s",err,strerror(err));
- return;
- }
-
- err = CGSSetWindowAlpha(gCGSConnID,gDesktopWindow,1.0);
- if (err != noErr) {
- fprintf(stderr,"CGSSetWindowAlpha failed: %08lX, %s",err,strerror(err));
- return;
- }
-
- gPowerPlant_CopyBitsProc = *gPowerPlant_CopyBitsVector;
- *gPowerPlant_CopyBitsVector = &PowerPlant_CopyBitsPatch;
-
- GetWindowBounds(gDesktopWindowRef,kWindowContentRgn,&bounds);
- InvalWindowRect(gDesktopWindowRef,&bounds);
-
- fprintf(stderr,"FinderPatch installed: pid = %d\n",getpid());
- return;
- }
-
-
-
- void PowerPlant_CopyBitsPatch(const BitMap *srcBits,const BitMap *dstBits,const Rect *srcRect,
- const Rect *dstRect,SInt16 mode,RgnHandle maskRgn)
- {
- SInt32 vdex,hdex;
- CGRect bounds;
- UInt32 depth;
- SInt32 rows;
- void *data[2];
- UInt8 *base,*baseAddr;
- PixMap *pm;
- SInt32 width,height;
- OSStatus err;
- static int once = 1;
-
- if (once)
- {
- pm = (PixMap*)srcBits;
- width = pm->bounds.right - pm->bounds.left;
- height = pm->bounds.bottom - pm->bounds.top;
- baseAddr = *(UInt8**)pm->baseAddr;
- rows = pm->rowBytes & 0x3FFF;
-
- for (vdex = 0;vdex < height;vdex += 1)
- {
- base = baseAddr;
- base += rows * vdex;
-
- for (hdex = 0;hdex < width;hdex += 1)
- ((UInt32*)base)[hdex] = 0x0F010201;
- }
-
- once = 0;
- }
-
- gPowerPlant_CopyBitsProc(srcBits,dstBits,srcRect,dstRect,mode,maskRgn);
-
- // Poor mans transparency hack
- err = CGSLockWindowBits(gCGSConnID,gDesktopWindow,&bounds,&depth,&data[0],&rows);
- if (err != noErr) {
- fprintf(stderr,"CGSLockWindowBits failed: %08lX, %s",err,strerror(err));
- return;
- }
-
- for (vdex = dstRect->top;vdex < dstRect->bottom;vdex += 1)
- {
- base = (UInt8*)data[0];
- base += rows * vdex;
-
- for (hdex = dstRect->left;hdex < dstRect->right;hdex += 1)
- if ((((UInt32*)base)[hdex] & 0x00FFFFFF) == 0x00010201)
- ((UInt32*)base)[hdex] = 0x0F000000;
- }
-
- err = CGSUnlockWindowBits(gCGSConnID,gDesktopWindow,NULL);
- if (err != noErr) {
- fprintf(stderr,"CGSUnlockWindowBits failed: %08lX, %s",err,strerror(err));
- return;
- }
- }
-